

import java.io.*;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.Scanner;

public class Zijieliu {

    public static void main(String[] args){

        String str = "";
        try(
//                InputStream in = new FileInputStream(new File("C:\\Users\\dell\\Desktop\\1.txt")); //InputStream 和 OutputStream为抽象类，无法直接使用，需要使用其子类实现功能
//                OutputStream out = new FileOutputStream(new File("C:\\Users\\dell\\Desktop\\2.png"));
//                Reader reader = new FileReader("C:\\Users\\dell\\Desktop\\1.txt");
//                Writer writer = new FileWriter("C:\\Users\\dell\\Desktop\\2.txt");  //一定要注意关流，否则就用try resource 语句
//                Reader reader1 = new InputStreamReader(System.in); //转换流
//                BufferedReader reader2 = new BufferedReader(new InputStreamReader(new FileInputStream("C:\\Users\\dell\\Desktop\\1.txt"))); //buffered带缓冲区的，可以读取行
//                BufferedWriter writer1 = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("C:\\Users\\dell\\Desktop\\2.txt")))
//                DataInputStream in = new DataInputStream(new FileInputStream("C:\\Users\\dell\\Desktop\\2.dat"));
//                DataOutputStream out = new DataOutputStream((new FileOutputStream("C:\\\\Users\\\\dell\\\\Desktop\\\\2.dat")));

                //序列化 反序列化
                ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("C:\\Users\\dell\\Desktop\\3.dat"));
                ObjectInputStream in = new ObjectInputStream(new FileInputStream("C:\\Users\\dell\\Desktop\\3.dat"));  //必须先out之后，才能 in，先写后读


        )
        {
            //序列化：将内容序列化到磁盘中  反序列化：从磁盘中读取
            //String 这个类是可以被序列化的，源码中实现了Serializable接口，没有实现Serializable接口的是不能被序列化的
            int [] numbers = {1,2,4,3,7};
            String [] strs = {"laowang","axiha"};
            out.writeObject(numbers);
            out.writeObject(strs);
            out.flush();  //由于操作过快，需要将流刷新
            out.close();

            int [] numbers1 = (int[])in.readObject();
            String[] strs1 = (String[])in.readObject();
            System.out.println(Arrays.toString(numbers1));
            System.out.println(Arrays.asList(strs1).toString());
            out.flush();
            out.close();




//            out.writeUTF("laowang");
//            out.writeDouble(5241.55);
//
//            System.out.println(in.readUTF());
//            System.out.println(in.readDouble());




//            String n;
//            while((n = reader2.readLine())!=null)
//            {
//                System.out.println(n);
//                writer1.write(n);
//                writer1.newLine();//换行
//            }



//            int n;
//            while ((n = reader.read())!=-1){
//                System.out.print((char)n);
//                writer.write(n);
//            }





//            byte [] buff = new byte[512];
//            int n;
//            while((n = in.read(buff))!=-1){ //读取流时，若没有内容时则返回-1，所以当不是-1时就继续读取,存入数组
//                str = str + new String(buff,0,n); //读取buff，从第0个开始读，读到第n个
//                buff = new byte[512]; //读完后将数组清空
//            }
//            System.out.println(str);

        }
         catch(Exception e){
            e.printStackTrace();
        }

    }
}
